package com.example.demo.proxy.jdk.handler;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ProxyHandler implements InvocationHandler {

    private Object proxied;

    public ProxyHandler(Object proxied) {
        this.proxied = proxied;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("proxy class:" + proxy.getClass() + "\nproxy method:" + method.getName());
        try{
            System.out.println("方法执行前");
            Object invoke = method.invoke(proxied, args);
            System.out.println("方法执行后的值是："+invoke);
            return invoke;
        }catch (InvocationTargetException e){
            throw e.getCause();
        }
    }
}
